package com.hnjowe.webdb;

import java.sql.*;
import javax.sql.DataSource;
import javax.naming.*;
import org.apache.log4j.Logger;

/**
 * 数据库连接
 * 卓威科技
 * @author 王秀武
 * @version 1.0
 */
public class DBConnection {
	private static Logger log = Logger.getLogger(DBConnection.class.getName());
    public Connection getConnection() throws Exception {
        try {
          Context initContext = new InitialContext();
          Context envContext  = (Context)initContext.lookup("java:/comp/env");
          DataSource ds = (DataSource)envContext.lookup("jdbc/mysql");
          return ds.getConnection();
        }catch (Exception ex) {
        	log.error(ex);
            throw ex;
        }
    }
}
